package com.example.dao;

import com.example.entity.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 数据访问类
 * @author 李平
 * @date 2022-4-30
 */
@Component
public class TestDao {

    @Autowired
    @Qualifier("apiJdbcTemplate")
    protected JdbcTemplate jdbcTemplate;

    /**
     * 查询全部
     * @return List<Test>
     */
    public List<Test> getAll(){
        String sql = String.format("SELECT * FROM test");
        List<Test> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Test.class));

        return query != null || query.size() > 0 ? query : null;
    }
}
